<template>
    <div class="M_box">
      <div class="me_header">
        <img @click="bac()" :src="'./static/lyl/back.png'" alt="">
        <span>{{user_login}}</span>
        <img :src="'./static/lyl/san.png'" alt="">
      </div>
      <video v-if="video.length" :src="video" controls width="100%"></video>
      <div v-html="html"></div>
      <div class="m_footer">
        <span>分享</span>
        <span @click="follow()">{{status?'已关注':'关注'}}</span>
      </div>

      <transition name="van-slide-right">
        <div v-show="visible" class="tran_right">{{Fade}}</div>
      </transition>
    </div>
</template>

<script>
  import * as search from "../../../api/search.js"
    export default {
      name: "Mechanism",
      data(){
        return {
          Fade:'',
          visible:false,
          video:'',
          html:null,
          status:0,
          user_login:''
        }
      },
      mounted(){
        //获取用户昵称
        let par = {user_id:this.$route.query.id};
        search.userinfo(par).then(res=>{
          console.log('用户昵称',res)
          this.user_login = res.data.user_login
        });
        //机构或达人简介
        let parms = {user_id:this.$store.state.user_id,uid:this.$route.query.id};
        search.userDetail(parms).then(res=>{
          console.log('简介',res);
          this.html = res.data.content;
          this.video = res.data.video;
          this.status = res.data.status
        })
      },
      methods:{
        bac(){
          history.go(-1)
        },
        follow(){
          if (this.status==0){
            this.status = 1;
            let flow = {follow_id:this.$route.query.id,user_id:this.$store.state.user_id,status:1};
            search.follow(flow).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              console.log(res);
            })
          } else{
            this.status = 0;
            let flow = {follow_id:this.$route.query.id,user_id:this.$store.state.user_id,status:0};
            search.follow(flow).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              console.log(res);
            })
          }
        }
      }
    }
</script>

<style scoped>
  .M_box{
    padding: 80px 0;
  }
 .me_header{
   background: #fff;
   border-bottom: 2px solid #dcdcdc;
   position: fixed;
   left: 0;
   top: 0;
   width: 100%;
   box-sizing: border-box;
   padding: 20px 40px;
   display: flex;
   justify-content: space-between;
 }
 .me_header img:nth-child(1){
   width: 25px;
   height: 40px;
 }
 .me_header span{
   font-size: 32px;
 }
 .me_header img:nth-child(3){
   align-self: center;
   width: 60px;
 }
 .m_footer{
   position: fixed;
   bottom: 0;
   width: 100%;
   height: 80px;
   display: flex;
 }
 .m_footer span{
   width: 50%;
   flex-grow: 1;
   font-size: 32px;
   background: #d8d8d8;
   height: 100%;
   line-height: 80px;
   text-align: center;
 }
 .m_footer span:nth-child(2){
   background: #cbcbcc;
   border-left: 2px solid #dcdcdc;
   border-right: 2px solid #dcdcdc;
 }

  .tran_right{
    width: 220px;
    height: 60px;
    border-radius: 10px;
    text-align: center;
    line-height: 60px;
    font-size: 30px;
    top: 50%;
    left: 50%;
    position: fixed;
    background: rgba(0,0,0,0.6);
    color: #fff;
  }
</style>
